import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.red,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  int _counter = 0;
  TextStyle blackStyle = TextStyle(color: Colors.black54, fontWeight: FontWeight.bold, fontSize: 10);
  TextStyle redStyle = TextStyle(color: Colors.red, fontWeight: FontWeight.normal, fontSize: 20);

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      // print("单次frame绘制回调$timeStamp");
    });
    WidgetsBinding.instance.addPersistentFrameCallback((timeStamp) {
      // print("实时frame绘制回调$timeStamp");
    });
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

  void _incrementCounter() {
    setState(() {});
    _counter--;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: CustomScrollView(
          slivers: <Widget>[
            SliverAppBar(
              title: Text('这是标题'),
              floating: true,
              flexibleSpace: Image.network(
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb.zol-img.com.cn%2Fdesk%2Fbizhi%2Fimage%2F1%2F1680x1050%2F1349289433496.jpg&refer=http%3A%2F%2Fb.zol-img.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1622370081&t=a6fba468c7024896c6459607463e177a',
                fit: BoxFit.cover,
              ),
              expandedHeight: 200,
            ),
            SliverList(
                delegate: SliverChildBuilderDelegate(
                    (context, index) => ListTile(
                          leading: Icon(Icons.map),
                          title: Text('第$index条数据'),
                          subtitle: Text('$index'),
                        ),
                    childCount: 50))
          ],
        ),
        // ListView.separated(
        //   scrollDirection: Axis.vertical,
        //   // itemExtent: 150,
        //   itemCount: 5,
        //   itemBuilder: (BuildContext context, int index) =>
        //       ListTile(
        //         leading: Icon(Icons.map),
        //         title: Text('第$index条数据'),
        //         subtitle: Text('$index'),
        //       ),
        //   separatorBuilder: (BuildContext context, int index) =>
        //   index % 2 == 0 ? Divider(color: Colors.red) : Divider(color: Colors.black),
        // )
        // Column(
        //   mainAxisAlignment: MainAxisAlignment.center,
        //   children: <Widget>[
        //     ListView(
        //       children: <Widget>[
        //         ListTile(leading: Icon(Icons.map), title: Text('地图')),
        //         ListTile(leading: Icon(Icons.mail), title: Text('邮箱')),
        //         ListTile(leading: Icon(Icons.games), title: Text('游戏')),
        //       ],
        //     ),
        //     FloatingActionButton(
        //       onPressed: () => print("点击了FloatingActionButton"),
        //       child: Text('这是一个按钮'),
        //     ),
        //     RaisedButton(
        //       onPressed: () => print('点击了RaisedButton'),
        //       child: Text('这是2号按钮'),
        //     ),
        //     FlatButton(
        //       color: Colors.red,
        //       shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
        //       colorBrightness: Brightness.dark,
        //       onPressed: () => print('点击了FlatButton按钮'),
        //       child: Row(
        //         children: <Widget>[
        //           Icon(Icons.add),
        //           Text('添加'),
        //         ],
        //       ),
        //     ),
        //     FadeInImage.assetNetwork(
        //       placeholder: 'assets/loading.gif',
        //       image:
        //           'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Ff46bbfd163fb833aa40c224ced4b395b00219deb43a35-RmFfBl_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1622365868&t=776dd697a2dbcbc25a87e3ec2d6daa8e',
        //       width: 200,
        //       height: 200,
        //       fit: BoxFit.contain,
        //     ),
        //     Text.rich(
        //       TextSpan(children: <TextSpan>[
        //         TextSpan(text: '文本是视图系统中常见的控件，它用来显示一段特定样式的字符串，类似', style: blackStyle),
        //         TextSpan(text: 'Android', style: redStyle),
        //         TextSpan(text: '中的', style: blackStyle),
        //         TextSpan(text: 'TextView', style: redStyle)
        //       ]),
        //       textAlign: TextAlign.center,
        //     ),
        //     Text(
        //       '文本是视图系统中的常见控件，用来显示一段特定样式的字符串，就比如Android里的TextView，或是iOS中的UILabel。',
        //       textAlign: TextAlign.center,
        //       style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20, color: Colors.red),
        //     ),
        //     Text(
        //       'You have pushed the button this many times:',
        //     ),
        //     Text(
        //       '$_counter',
        //       style: Theme.of(context).textTheme.headline4,
        //     ),
        //   ],
        // ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    print("$state");
    super.didChangeAppLifecycleState(state);
  }
}
